#!/usr/local/bin/perl

# This perl script calls herest repeatedly to build a sequence
# of model sets, each set in the sequence being 1 single embedded
# reestimation of the previous
#
#     usage: hbuild.prl fromN toN
#
# Example - hbuild.prl 2 4  is equivalent to the sequence
#               herest HTE hmm1 hmm2
#               herest HTE hmm2 hmm3
#               herest HTE hmm3 hmm4
# Note that this script must be executed in the directory holding
# hmm1, hmm2 etc.
#
# Copyright (c) Steve Young & Phil Woodland, 1992, 1993
# Last Updated 14/5/93
#
# convert to perl by TL 7/1998
#

if ( $#ARGV != 1 ) {
   die "usage: hbuild.prl fromN toN\n";
}

open(LOGFILE,">blog") or die "Can't open blog file\n";
printf LOGFILE "Build started at " . scalar localtime(time) . "\n"; 
$i=$ARGV[0];
while ( $i <= $ARGV[1] ) {
   $j = $i - 1;
   if ( -d "hmm$i" ) {
      die "hbuild: trying to overwrite hmm$i\n";
   }
   printf LOGFILE "Building hmm$i from hmm$j\n";
   system("perl $ENV{RMSCRIPTS}\\herest.prl HTE hmm$j hmm$i");
   $i++;
}
printf LOGFILE "Build finished at " . scalar localtime(time) . "\n"; 
close (LOGFILE);
